package com.yugao.fintech.antelope.mps.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yugao.fintech.antelope.mps.model.rqrs.template.MsgTemplatePageReq;
import com.yugao.fintech.antelope.mps.model.rqrs.template.MsgTemplateResp;
import com.yugao.fintech.antelope.mps.model.rqrs.template.MsgTemplateSaveReq;
import com.yugao.fintech.antelope.mps.model.rqrs.template.MsgTemplateUpdateReq;
import com.yugao.fintech.antelope.mps.service.MsgTemplateService;
import com.yugao.fintech.antelope.base.ram.ActionType;
import com.yugao.fintech.antelope.base.ram.RamResource;
import com.yugao.fintech.framework.core.response.Resp;
import com.yugao.fintech.framework.security.xss.core.XssCleanIgnore;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "消息模板")
@RestController
@RequestMapping("/msgTemplate")
public class MsgTemplateController {
    @Autowired
    private MsgTemplateService msgTemplateService;

    @ApiOperation(value = "分页消息模板")
    @GetMapping("/pageMsgTemplate")
    @RamResource(action = "msg:msgTemplate:query", name = "查询消息模板", type = ActionType.READ)
    public Resp<IPage<MsgTemplateResp>> pageTemplate(@Validated MsgTemplatePageReq req) {
        return Resp.ok(msgTemplateService.pageTemplate(req));
    }

    @ApiOperation(value = "通过id查找消息模板")
    @GetMapping("/getMsgTemplate")
    @RamResource(action = "msg:msgTemplate:query", name = "查询消息模板", type = ActionType.READ)
    public Resp<MsgTemplateResp> getTemplate(@RequestParam(value = "id") Long id) {
        return Resp.ok(msgTemplateService.getTemplate(id));
    }
  
    @ApiOperation(value = "保存消息模板")
    @PostMapping("/saveMsgTemplate")
    @XssCleanIgnore({"templateConfig"})
    @RamResource(action = "msg:msgTemplate:save", name = "保存消息模板", type = ActionType.WRITE)
    public Resp<?> saveTemplate(@Validated @RequestBody MsgTemplateSaveReq req) {
        return Resp.ok(msgTemplateService.saveTemplate(req));
    }
  
    @ApiOperation(value = "更新消息模板")
    @PostMapping("/updateMsgTemplate")
    @XssCleanIgnore({"templateConfig"})
    @RamResource(action = "msg:msgTemplate:update", name = "更新消息模板", type = ActionType.WRITE)
    public Resp<?> updateTemplate(@Validated @RequestBody MsgTemplateUpdateReq req) {
        return Resp.ok(msgTemplateService.updateTemplate(req));
    }

    @ApiOperation(value = "更新消息模板状态")
    @PostMapping("/updateTemplateStatus")
    @RamResource(action = "msg:msgTemplate:updateStatus", name = "更新消息模板状态", type = ActionType.WRITE)
    public Resp<?> updateTemplateStatus(@RequestParam(value = "status") Boolean status,
                                        @RequestParam("id") Long id) {
        msgTemplateService.updateTemplateStatus(id, status);
        return Resp.ok();
    }
  
    @ApiOperation(value = "批量删除消息模板")
    @DeleteMapping("/batchDeleteMsgTemplate")
    @RamResource(action = "msg:msgTemplate:delete", name = "删除消息模板", type = ActionType.WRITE)
    public Resp<?> batchDeleteTemplate(@RequestParam(value = "ids") List<Long> ids) {
        return Resp.ok(msgTemplateService.batchDeleteTemplate(ids));
    }
  
    @ApiOperation(value = "删除消息模板")
    @DeleteMapping("/deleteMsgTemplate")
    @RamResource(action = "msg:msgTemplate:delete", name = "删除消息模板", type = ActionType.WRITE)
    public Resp<?> deleteTemplate(@RequestParam(value = "id") Long id) {
        return Resp.ok(msgTemplateService.deleteTemplate(id));
    }
}
